<template>
  <div class="detailPageCss detail_container">
    <div class="head_title" v-if="!detailForm.id">上传执法文书</div>
    <div class="head_title" v-else-if="detailForm.id && isEdit">编辑执法文书</div>
    <div class="head_title" v-else-if="detailForm.id && !isEdit">查看执法文书</div>
    <el-divider></el-divider>
    <div class="bodyCss">
      <el-form ref="expertForm" :model="params" label-width="140px" :rules="rules">
        <el-row>
          <el-form-item label="文书类型">
            <el-select v-model="params.documentType" placeholder="请选择" style="width:100%;"  >
              <el-option
                  v-for="item in documentTypeList"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue">
              </el-option>
            </el-select>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="文书编号">
            <el-input v-model="params.documentNumber" placeholder="请输入"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="文书上传">
            <file-upload v-model="params.documentFileUrl" :file-type="fileType" :file-size="5" limit="1"/>
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <div class="bottomBtnCss">
      <el-button @click="sureForm('expertForm')" type="primary" v-if="!detailForm.id || isEdit">确认提交</el-button>
      <el-button @click="isEdit = true" type="primary" v-if="detailForm.id && !isEdit">编辑</el-button>
      <el-button @click="show = false">返回</el-button>
    </div>
  </div>



</template>

<script>
export default{
  data () {
    return {
      params:{
        id: null,
        documentType: null,
        documentNumber: null,
        documentFileUrl: null,
        createId: null,
        createBy: null,
        createTime: null,
        updateId: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
      },
      rules: {
      },
      fileType: ['docx', 'doc'],
    }
  },
  props: {
    editVisible: {
      type: Boolean,
      default: () => {
        return false
      }
    },
    detailForm: {
      type: Object,
      default: () => {
        return {}
      }
    },
    isEdit:{
      type:Boolean,
      default:()=>{
        return false
      }
    },
    documentTypeList:{
      type:Object,
      default: () => {
        return []
      }
    }
  },
  watch:{

  },
  computed: {
    show: {
      get () {
        return this.editVisible
      },
      set (val) {
        this.$emit('update:editVisible', val)
      }
    },
  },
  created () {
    if(this.detailForm.id){
      this.params = {...this.detailForm}
    }
  },
  methods: {
    // 确认
    sureForm(formName) {
      this.$refs [formName].validate((valid) => {
        if (valid) {
          if(this.detailForm.id){
            this.$emit('submitForm', this.params,this.detailForm.id)
          }else{
            this.$emit('submitForm', this.params)
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });

    },
  }

}
</script>

<style scoped="scoped" lang="scss">
.titile_txt{
  font-family: Source Han Sans SC, Source Han Sans SC;
  font-weight: bold;
  font-size: 16px;
  color: #333333;
  line-height: 19px;
  margin-bottom: 15px;
}
.detailPageCss{
  padding: 20px;
  border-radius: 10px;
  height: calc( 100vh - 66px - 40px);
  display: flex;
  flex-direction: column;
  .titleCss{
    text-align: center;
    font-size: 18px;
    font-weight: bold;
  }
  .bodyCss{
    margin-top: 40px;
    width: 500px;
    margin-left: 50%;
    transform: translateX( calc( -50% - 70px ));
  }
  .bottomBtnCss{
    margin-top: auto;
    text-align: right;
  }
}

</style>
